package net.chamerling.blog.petalsclient;

import java.io.File;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;

import org.ow2.petals.kernel.ws.api.DeploymentService;
import org.ow2.petals.kernel.ws.api.PEtALSWebServiceException;
import org.ow2.petals.kernel.ws.api.to.AttachmentDescriptor;
import org.ow2.petals.kernel.ws.client.PetalsClient;
import org.ow2.petals.kernel.ws.client.PetalsClientFactory;

/**
 * Sample which is using the petals-kernel-wsclient library
 * 
 * @author chamerling
 * 
 */
public class App {

	public static void main(String[] args) {

		try {
			// get a client
			PetalsClient client = PetalsClientFactory.getInstance().getClient(
					"http://localhost:7600/petals/ws", 20000);

			// 'upload' the SA in the artifact repository
			File saFile = new File("sa.zip");
			AttachmentDescriptor ds = new AttachmentDescriptor();
			ds.setAttachment(new DataHandler(new FileDataSource(saFile)));
			client.getArtifactRepositoryService().addArtifact(ds);

			// Deploy the SA and start it
			String saId = "my-sa-id";
			DeploymentService dClient = client.getDeploymentService();
			dClient.deploy(saId);
			dClient.start(saId);
			
		} catch (PEtALSWebServiceException e) {
			e.printStackTrace();
		}

	}
}
